package demo.pattern.factory.sample;

import demo.pattern.factory.entity.Mouse;
import demo.pattern.factory.entity.MouseA;
import demo.pattern.factory.entity.MouseB;

/**
 * 简单工厂设计模式
 * 部分遵循“开闭原则（对拓展开放，对修改关闭）”：
 * 当需要其他的鼠标时，比如MouseC，直接实现Mouse接口即可，拓展，没有修改原来代码；但是createMouse方法需要修改原来代码
 */
public class SampleMouseFactory {
	public static Mouse createMouse(int type){
		switch (type) {
			case 0: return new MouseA();
			case 1: return new MouseB();
			default: return new MouseA();
		}
	}

	public static void main(String[] args) {
		Mouse mouse = SampleMouseFactory.createMouse(1);
		mouse.print();
	}
}
